'MsgBox csvtojson("dataset.csv")

Function csvtojson(filename)
Dim datacarr()
Dim fso,  file,  msg
Set  fso = CreateObject ("Scripting.FileSystemObject")
Set  file =  fso.OpenTextFile (filename,1)

label=file.ReadLine
labelarr=Split(label,",",-1,1)
csvccount=UBound(labelarr)
If csvccount>=2 Then
	ReDim datacarr(csvccount)
	
	Do While Not  file.AtEndOfStream 
		data =  file.ReadLine
		dataarr=Split(data,",",-1,1)
		For dataseti=0 To csvccount-1
			datacarr(dataseti)=smalldataset(datacarr(dataseti),dataarr(0),dataarr(dataseti+1))
			'MsgBox datacarr(dataseti)
		Next
	Loop 
	
	For labelseti=0 To csvccount-1
		result=	middataset(result,labelarr(labelseti+1),datacarr(labelseti))
		'MsgBox result
	Next
	
	file.Close  
	Set file = Nothing
	Set fso = Nothing
	csvtojson=result
Else
	csvtojson="error"
End if

End Function




public function smalldataset(old,item1,item2)
if old="" or isnull(old) then
	smalldataset="["+cstr(item1)+","+cstr(item2)+"]"
else
	smalldataset=old+",["+cstr(item1)+","+cstr(item2)+"]"
end if
end function

public function middataset(old,label,item)
If old="" Or IsNull(old) Then
	middataset=""""+cstr(label)+""": {label:"""+cstr(label)+""",data:["+item+"]}"
Else
	middataset=old+","""+cstr(label)+""": {label:"""+cstr(label)+""",data:["+item+"]}"
End if
end function